import store from '@/store'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/', component: () => import('@/views/Home/index.vue')
  },
  {
    path: '/login', component: () => import('@/views/Login/index.vue')
  },
  {
    path: '/musiclistdetail', component: () => import('@/views/MusicListDetail/index.vue')
  },
  {
    path: '/search', component: () => import('@/views/Search/index.vue')
  },
  {
    path: '/searchDetail', component: () => import('@/views/SearchDetail/index.vue')
  },
  {
    path: '/userZone', component: () => import('@/views/UserZone/index.vue'),
    beforeEnter: (to, from, next) => {
      if (store.state.isLogin) {
        next()
      } else {
        next('/login')
      }
    }
  },
  {
    path: '/commentDetail', component: () => import('@/views/CommentDetail/index.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory('/'),
  routes
})
router.beforeEach((to, from) => {
  if (to.path === '/login' || to.path === '/commentDetail' || !store.state.playList[0].id) {
    store.commit('updateFooterMusicShow', false)
  } else {
    store.commit('updateFooterMusicShow', true)
  }
})

export default router
